#include "JPEGVideoSource.hh"
#include "UsageEnvironment.hh"

#define JPEG_HEADER_MAX_SIZE 623

class IPCameraJPEGVideoSource :
	public JPEGVideoSource
{
public:
	static IPCameraJPEGVideoSource* createNew(UsageEnvironment& env, char* url);
	bool isFull;
	bool SetJpeg(char* jpeg, int length);

public:
    virtual u_int8_t type();
    virtual u_int8_t qFactor();
    virtual u_int8_t width(); // # pixels/8 (or 0 for 2048 pixels)
    virtual u_int8_t height(); // # pixels/8 (or 0 for 2048 pixels)
	u_int8_t const* quantizationTables(u_int8_t& precision, u_int16_t& length);

protected:
	IPCameraJPEGVideoSource(UsageEnvironment& env, char* url);
	~IPCameraJPEGVideoSource(void);

	char* rtspURL;

	

private:
    // redefined virtual functions:
    virtual void doGetNextFrame();
    virtual void doStopGettingFrames();
    //virtual double getAverageLevel() const;
	int setParamsFromHeader( const unsigned char *fJPEGHeader );

private:
	u_int8_t fLastWidth;
	u_int8_t fLastHeight;
	u_int8_t * qTable;

	unsigned m_skipCounter;
public:
	int		prevImageLength;
	int		int_stream_id;
	void*	ptr_frame_buffer;
};
